import matplotlib.pyplot as plt
import numpy as np

# 数据
labels = ['Q1', 'Q2', 'Q3', 'Q4']
product_a = [50, 60, 55, 70]
product_b = [30, 40, 45, 50]
product_c = [20, 30, 35, 40]

x = np.arange(len(labels))  # 标签位置

# 创建堆积柱形图
fig, ax = plt.subplots()
ax.bar(x, product_a, label='Product A')
ax.bar(x, product_b, bottom=product_a, label='Product B')
ax.bar(x, product_c, bottom=np.array(product_a) + np.array(product_b), label='Product C')

# 设置标签和标题
ax.set_xlabel('Quarter')
ax.set_ylabel('Sales')
ax.set_title('Stacked Sales by Product and Quarter')
ax.set_xticks(x)
ax.set_xticklabels(labels)
ax.legend()

plt.rcParams['font.sans-serif']=['SimHei']

plt.show()
